﻿using LxCore;

namespace LxCore
{
    public class StepCenter : JsObject
    {
        private IterationStepSet _IterationStep = new();
        public IterationStepSet IterationStep
        {
            get { return _IterationStep; }
            set { _IterationStep = value; RaisePropertyChanged(nameof(IterationStep)); }
        }
        private TimeStepSet _TimeStep = new();
        public TimeStepSet TimeStep
        {
            get { return _TimeStep; }
            set { _TimeStep = value; RaisePropertyChanged(nameof(TimeStep)); }
        }

        private int _CurrentTotalStep;
        public int CurrentTotalStep
        {
            get { return _CurrentTotalStep; }
            set { _CurrentTotalStep = value; RaisePropertyChanged(nameof(CurrentTotalStep)); }
        }
        public void ClearHistory()
        {
            IterationStep.CurrentStep = 0;
            TimeStep.CurrentStep = 0;
            TimeStep.CurrentTime = 0;
            CurrentTotalStep = 0;
        }
        public override void FromJsonKV(string key, IJsonReader jsReader)
        {
            switch (key)
            {
                case nameof(IterationStep): jsReader.ReadObject(IterationStep); break;
                case nameof(TimeStep): jsReader.ReadObject(TimeStep); break;
                case nameof(CurrentTotalStep): CurrentTotalStep = jsReader.ReadInt(); break;
                default: base.FromJsonKV(key, jsReader); break;
            }

        }
        public override void ToJsonKV(IJsonWriter jsWriter)
        {
            base.ToJsonKV(jsWriter);
            var tdt = LxSim.Sim.Physics.TimeDiscreteType;
            if (tdt == TimeDiscreteTypes.Steady || tdt == TimeDiscreteTypes.Implicit_2nd ||tdt== TimeDiscreteTypes.Implicit_1st)
            {
                jsWriter.WriteObject(nameof(IterationStep), IterationStep);
            }  
            if(LxSim.Sim.Physics.IsTransient)
            {
                jsWriter.WriteObject(nameof(TimeStep), TimeStep);
            }       
            jsWriter.WriteInt(nameof(CurrentTotalStep), CurrentTotalStep);
        }
    }
}
//public void Clear(ClearTypes clearType)
//{
//    switch (clearType)
//    {
//        case ClearTypes.ClearSim:
//        case ClearTypes.ClearMesh:
//        case ClearTypes.ClearSolutions:
//            IterationStep.CurrentStep = 0;
//            TimeStep.CurrentStep = 0;
//            CurrentTotalStep = 0;
//            break;
//        case ClearTypes.ClearCalcWorks://参数有变更时               
//            break;
//        case ClearTypes.None:
//        default:
//            break;
//    }
//}